package com.taiji.controller;


import com.taiji.domain.CommonResult;
import com.taiji.domain.Payment;
import com.taiji.domain.Student;
import com.taiji.mapper.StuMapper;
import com.taiji.service.StuService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Stu")
public class StuController {
    @Resource
    private StuService service;
    @RequestMapping("/get/{id}")
    public CommonResult<Student> finInfoById(@PathVariable("id") Integer id){
        Student student = service.finById(id);
        if (student!=null){
            return new CommonResult(200,"查询成功8001",student);
        }else {
            return new CommonResult(400,"没有查找到对应的数据,ID="+id,null);
        }
    }
    @RequestMapping("/add")
    public CommonResult addInfo(@RequestBody Student student){
        int res = service.addInfo(student);
        if (res>0){
            return new CommonResult(200,"插入数据库成功",res);
        }else {
            return new CommonResult(400,"插入数据失败",null);
        }
    }
    @RequestMapping("/del/{id}")
    public CommonResult addInfo(@PathVariable("id") Integer id){
        int res = service.delInfoById(id);
        if (res>0){
            return new CommonResult(200,"删除数据成功",res);
        }else {
            return new CommonResult(400,"删除数据失败",null);
        }
    }

}
